<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


/**
 * 数组重新按某一索引进行分组
 * @param $array
 * @param $filed
 * @return array
 */
function group_array($array,$filed){
    $new = [];
    foreach ($array as $key=>$value){
        $new[$value[$filed]][] = $value;
    }
    return $new;
}

//按照分组，并且是hash索引
function group_array_hash($array,$filed){
    $new = [];
    foreach ($array as $key=>$value){
        $new[$value[$filed]][ $value['name'] ] = $value['value'];
    }
    return $new;
}


function jdebug($var){
    if(gettype($var)=='object'){
        Header('Content-type: text/html;charset=utf8');
        echo "<pre>\n"; var_dump($var); echo "</pre>";
        exit;
    }else{
        Header('Content-type: application/json;charset=utf8');
        echo json_encode($var, JSON_UNESCAPED_UNICODE| JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
        exit;
    }
}

function da_jencode($var){
    return json_encode($var, JSON_UNESCAPED_UNICODE| JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
}

function da_jdecode($str, $retArray=false){
    $str = trim( preg_replace('/[\x00-\x1F\x7F]/', '', $str) );
    return json_decode($str, $retArray);
}
